package code20210926;

public class C198 {

	public static void main(String[] args) {
		int[] nums = {2,7,9,3,1};
		System.out.println(new C198().rob(nums));
	}
	public int rob(int[] nums) {
		int n = nums.length;
		int[] dp = new int[n+2];
		dp[0] = 0;
		dp[1] = 0;
		dp[2] = nums[0];
		for(int i=3;i<=(n+1);i++) {
			dp[i] = Math.max(dp[i-2]+nums[i-2], dp[i-3]+nums[i-3]);
		}
		return dp[n+1];
    }

}
